package com.example.Config;

import com.alibaba.druid.support.json.JSONUtils;
import com.example.Interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.w3c.dom.ls.LSOutput;

import java.util.ArrayList;
import java.util.List;

//配置拦截器
@Configuration
public class LoginConfig implements WebMvcConfigurer {
    /**
     * 注册拦截器与配置黑名单与白名单
     */
    //创建需要注册拦截器对象

    LoginInterceptor loginInterceptor = new LoginInterceptor();
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //创建需要放行的路径并存储到List集合中
        List<String> list = new ArrayList<String>();
        //向集合中添加放行的资源
        list.add("/backend/api/**");
        list.add("/backend/images/**");
        list.add("/backend/food/**");
        list.add("/backend/js/**");
        list.add("/backend/page/login/**");
        list.add("/backend/plugins/**");
        list.add("/backend/style/**");
        list.add("/backend/**");
        //将自定义登录请求也放行
        list.add("/employee/login");
        list.add("/common/**");
        list.add("/front/page/**");
        list.add("/front/js/**");
        list.add("/front/styles/**");
        list.add("/front/images/**");
        list.add("/front/fonts/**");
        list.add("/front/api/**");
        list.add("/user/sendMsg");
        list.add("/user/login");
        list.add("/front/**");
        //注册拦截器
        registry.addInterceptor(loginInterceptor).addPathPatterns("/**").excludePathPatterns(list);
    }
}
